﻿using System;

namespace test_9_27_C_Sharp
{
    class GetAdd
    {
        public int Add(int x, int y)
        {
            return x + y;
        }
        public string Add(string str1, string str2)
        {
            string str3 = str1 + str2;
            return str3;
        }
    }
    class Program1
    {
        static void Main1(string[] args)
        {
            Console.WriteLine("我是叶豪方，这是我的上机作业5");
            Console.WriteLine("请输入两个数字:>");
            int a = Convert.ToInt32(Console.ReadLine());//获取数1
            int b = Convert.ToInt32(Console.ReadLine());//获取数2
            GetAdd sum = new GetAdd();//引用类
            Console.WriteLine("两数之和为:" + sum.Add(a, b));
            Console.WriteLine("请输入两组字符串:>");
            string str1 = Console.ReadLine();//获取串1
            string str2 = Console.ReadLine();//获取串2
            Console.WriteLine("两串之和为:" + sum.Add(str1, str2));
        }
    }
    class Vehice
    {
        double Speed = 80.0;//单位km/h
        double MaxSpeed = 180.0;//同上
        double Weight = 1744;//单位kg
        string Type = "GTR";
        public void Run()
        {
            Console.WriteLine("当前车辆正在行驶!");
        }
        public void Stop()
        {
            Console.WriteLine("当前车辆已停止!");
        }
        public void ShowVehiceInfo()
        {
            Console.WriteLine("\n" + "\t" + "当前速度为:" + Speed + "km/h");
            Console.WriteLine("\t" + "当前最大速度为:" + MaxSpeed + "km/h");
            Console.WriteLine("\t" + "当前车重:" + Weight + "kg");
            Console.WriteLine("\t" + "当前车辆型号为:" + Type + "\n");
        }
        public bool Modify(string type, double weight)
        {
            if (weight == 0)
            {
                Console.WriteLine("错误，车重不能为0!");
                return false;
            }
            Type = type;
            Weight = weight;
            return true;
        }
    }
    class Program2
    {
        static void Main2(string[] args)
        {
            Console.WriteLine("我是叶豪方，这是我的上机作业5");
            Vehice Car1 = new Vehice();
            Car1.Run();
            Console.WriteLine("当前车辆信息为:>");
            Car1.ShowVehiceInfo();
            Console.WriteLine("请输入想修改的信息(型号及车重):>");
            string type = Console.ReadLine();
            double weight = Convert.ToDouble(Console.ReadLine());
            if (Car1.Modify(type, weight))
            {
                Console.WriteLine("修改成功，更新车辆信息!");
                Car1.ShowVehiceInfo();
                Car1.Stop();
            }
            else
            {
                Console.WriteLine("修改失败!无法更新!");
                Car1.Stop();
            }
        }
    }
    class Program
    {
        class Rectangle
        {
            double Length;//长
            double Width;//宽
            public void RecInit()//初始化函数
            {
                Length = 0;
                Width = 0;
                Console.WriteLine("初始化成功!");
            }
            public bool SetLW(double x, double y)//赋值
            {
                if (x <= 0 || y <= 0)
                {
                    Console.WriteLine("输入长或宽不符合逻辑！错误！");
                    return false;
                }
                else
                {
                    Length = x;
                    Width = y;
                    Console.WriteLine("数据合法！赋值成功！");
                    return true;
                }
            }
            public double Area()//求面积
            {
                return Length * Width;
            }
            public double Girth()//求周长_自己加的
            {
                return (Length + Width) * 2;
            }
            public void menu()
            {
                Console.WriteLine("***************************");
                Console.WriteLine("***  1.初始化  2.赋值   ***");
                Console.WriteLine("***  3.求面积  4.求周长 ***");
                Console.WriteLine("***       0.退出        ***");
                Console.WriteLine("***************************");
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("我是叶豪方，这是我的上机作业5");
            Rectangle R1 = new Rectangle();
            int input = 1;
            while (input != 0)
            {
                R1.menu();
                Console.WriteLine("请输入选择:>");
                input = Convert.ToInt32(Console.ReadLine());
                switch (input)
                {
                    case 1:
                        R1.RecInit();
                        break;
                    case 2:
                        Console.WriteLine("请输入两个数:>");
                        double x = Convert.ToDouble(Console.ReadLine());
                        double y = Convert.ToDouble(Console.ReadLine());
                        if (R1.SetLW(x, y))
                            Console.WriteLine("成功!");
                        else
                            Console.WriteLine("失败!");
                        break;
                    case 3:
                        Console.WriteLine("面积为" + R1.Area());
                        break;
                    case 4:
                        Console.WriteLine("周长为" + R1.Girth());
                        break;
                    case 0:
                        Console.WriteLine("成功退出!");
                        break;
                    default:
                        Console.WriteLine("选择错误!");
                        break;
                }
            }
        }
    }
}
